package com.ai3d.rfid.common.utils;

/**
 * @ProjectName : Trias
 * @Author : weijinsong
 * @Time : 2023/4/17 16:59
 * @Description : 限制次数
 */
public class LimitingFrequencyUtils {
    //500毫秒以内只处理一次事件
    private static volatile long moreThanLastKeyTime = 0;
    private static volatile long lastKeyTime = 0;

    public static synchronized boolean moreThanLastKeyTime(int value) {
        long curTime = System.currentTimeMillis();
        moreThanLastKeyTime = curTime - lastKeyTime;
        if (moreThanLastKeyTime > 0) {
            // fit tdt time
            if (moreThanLastKeyTime < value) {
                lastKeyTime = curTime;
                return false;
            }
        }
        lastKeyTime = curTime;
        return true;
    }
}
